<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>策略管理 - 后台管理</title>
  <link rel="stylesheet" href="/static/base.css">
  <link rel="stylesheet" href="/static/components.css">
  <link rel="stylesheet" href="/static/pages.css">
  <link rel="stylesheet" href="/static/admin/admin.css">
</head>
<body>
  <div class="admin-layout">
    <!-- 顶部导航 -->
    <div class="admin-header">
      <h2>策略管理</h2>
      <div>
        <button class="btn" onclick="location.href='/'">返回前台</button>
        <button class="btn" onclick="logout()">退出</button>
      </div>
    </div>

    <!-- 主体内容 -->
    <div class="admin-main">
      <!-- 左侧导航（公共组件注入） -->
      <div class="admin-sidebar"></div>

      <!-- 右侧内容区域 -->
      <div class="admin-content">
        <div class="content-page active">
          <h3>策略管理概览</h3>
          <p class="page-description">管理选股策略的配置、执行和结果分析</p>

          <!-- 策略统计面板 -->
          <div class="strategy-stats">
            <h4>策略统计</h4>
            <div class="stats-grid">
              <div class="stat-item">
                <span class="stat-label">可用策略</span>
                <span id="strategy-count" class="stat-value">-</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">执行次数</span>
                <span id="execution-count" class="stat-value">-</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">成功率</span>
                <span id="success-rate" class="stat-value">-</span>
              </div>
            </div>
          </div>

          <!-- 快速操作 -->
          <div class="content-grid">
            <div class="content-card">
              <h4>策略配置</h4>
              <p>配置选股策略的执行参数和策略选择</p>
              <div class="card-actions">
                <button class="btn btn-primary" onclick="location.href='/admin/strategy-config'">进入配置</button>
              </div>
            </div>

            <div class="content-card">
              <h4>执行记录</h4>
              <p>查看策略执行的详细记录和历史数据</p>
              <div class="card-actions">
                <button class="btn btn-primary" onclick="location.href='/admin/execution-record'">查看记录</button>
              </div>
            </div>

            <div class="content-card">
              <h4>结果分析</h4>
              <p>分析策略执行结果的统计信息和分布情况</p>
              <div class="card-actions">
                <button class="btn btn-primary" onclick="location.href='/admin/result-analysis'">开始分析</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="/static/admin/components/sidebar.js"></script>
  <script>
    // 页面加载时获取策略统计信息
    document.addEventListener('DOMContentLoaded', function() {
      loadStrategyStats();
      injectAdminSidebar('/admin/strategy');
    });

    // 加载策略统计信息
    async function loadStrategyStats() {
      try {
        const response = await fetch('/admin/api/strategy/stats');
        const data = await response.json();
        
        if (data.success) {
          document.getElementById('strategy-count').textContent = data.stats.strategy_count || 0;
          document.getElementById('execution-count').textContent = data.stats.execution_count || 0;
          document.getElementById('success-rate').textContent = data.stats.success_rate || '0.0%';
        } else {
          console.error('获取策略统计失败:', data.error);
          // 使用默认值
          document.getElementById('strategy-count').textContent = '25';
          document.getElementById('execution-count').textContent = '0';
          document.getElementById('success-rate').textContent = '0.0%';
        }
      } catch (error) {
        console.error('加载策略统计失败:', error);
        // 使用默认值
        document.getElementById('strategy-count').textContent = '25';
        document.getElementById('execution-count').textContent = '0';
        document.getElementById('success-rate').textContent = '0.0%';
      }
    }

    // 退出登录
    async function logout(){
      try{ 
        await fetch('/admin/logout', {method:'POST'}); 
        location.href='/admin/login'; 
      }catch(e){ 
        location.href='/admin/login'; 
      }
    }
  </script>
</body>
</html>
